﻿@{
    ViewBag.Title = "Ins";
}
@section scripts
{   
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />       
    <script src="@Url.Content("~/Scripts/shared/share.js?v=")@ViewBag.version" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js?v=")@ViewBag.version" type="text/javascript"></script>  
    <script src="@Url.Content("~/Scripts/Bill/Bill.js?v=")@ViewBag.version" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/Print.js?v=")@ViewBag.version" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Bill/scan.js?v=")@ViewBag.version" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/zxx.drag.1.0.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js?v=")@ViewBag.version" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/gridlayout.js?v=")@ViewBag.version" type="text/javascript"></script>
    <script src="~/scripts/common/print.js?v=@ViewBag.version" type="text/javascript"></script>
    <style type="text/css">
        .window-mask {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
                height: 100%;
                filter: alpha(opacity=40);
                opacity: 0.40;
                font-size: 1px;
                overflow: hidden;
                display:none;
                background-color: gray;
            }
    </style>
}
<body>
   <form id="form1" runat="server" method="post" style="height: 100%">
    
<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table width = "1000px;">
        <tr>
            <td width = "1000px;">
                <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBills" plain="true" visible="@ViewBag.save">新增</a>
                <a class="mini-button" id="save" name="save" iconCls="icon-save" onclick="saveBill" plain="true" visible="@ViewBag.save">保存</a>             
                <a class="mini-button" id="addrow" name="addrow" iconCls="icon-addnew" onclick="addRow" plain="true" visible="@ViewBag.save">增行</a>
                <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeRow" plain="true" visible="@ViewBag.save">删行</a>
                <a class="mini-button" id="modify" name="modify" iconCls="icon-edit" onclick="modifys" plain="true" visible="@ViewBag.save">改单</a>
                <a class="mini-button" id="check" name="check" iconCls="icon-ok" onclick="checkBill" plain="true" visible="@ViewBag.check">审核</a>
                <span class="separator"></span>
                <a class="mini-menubutton" plain="true" iconCls="icon-expand" menu="#popupMenu">选项</a>
                <a class="mini-button" id="print" iconCls="icon-print" onclick="printBillMyseft" plain="true" visible="@ViewBag.print">打印</a>
                <a class="mini-button" id="getdata" iconCls="icon-collapse" onclick="getBillData" plain="true">浏览</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindowBill" plain="true">关闭</a>
            </td>
        </tr>
    </table>                 
</div>
    
    <div id = "DivHeader">
        <table style="width:770px;" cellpadding="0" cellspacing="1">
            <tr>
                <td width ="80px" align="right">供应商：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookUpSupply.cshtml") 
                </td>
                <td width ="80px" align="right">开单日期：</td>
                <td width ="190px">    
                    <input name="FDate" class="mini-datepicker" style="width:190px;"/>
                </td>
                 <td width ="80px" align="right">单据编号：</td>
                 <td width ="150px">    
                    <input name="FBillNo" class="mini-textbox" required="true"readonly="readonly"style="width:150px;"/>
                 </td>
            </tr>
            <tr>
                <td align="right">门店名称：</td>
                <td >
                    @Html.Partial("~/Views/Modular/LookupStockData.cshtml")
                </td>
                <td align="right">单据备注：</td> 
                <td >  
                    <input name="FRemark" class="mini-textbox"  style="width:190px;"/>  
                </td>
                <td align="right">单据状态：</td>
                <td >    
                    <input name="txtCheckFlag" class="mini-textbox" readonly="readonly"style="width:150px;"/></td>
            </tr>
            <tr>
                <td align="right">采购订单：</td>
                <td >
                    <input id="FBillNO_Pur" name ="FBillNO_Pur" class="mini-buttonedit"  style="width:199px;"  onbuttonclick="onGetSourceBill"/>                   
                </td>
                <td align="right"></td>                    
                <td >  
                    
                </td>
                <td align="right"></td>
                <td >    
                    
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        @Html.Partial("~/Views/Modular/Bill/InsDataGrid.cshtml")
    </div>

     @Html.Partial("~/Views/Modular/Bill/Footer.cshtml")
    </form>
    <input id="KInterID_Pur" name="KInterID_Pur" class="mini-hidden"/>
    <input id="type" name="type" value="@ViewBag.type" type="hidden"/>

    @Html.Partial("~/Views/Modular/Bill/ScanWin.cshtml")

    <!--menu-->
    <ul id="popupMenu" class="mini-menu" style="display:none;">
        <li id ="import" iconCls="icon-redo" onclick="ExcelImport" visible="@ViewBag.save">从Excel文件导入</li>        
	    <li id ="ScanAdd" iconCls="icon-find" onclick="ScanAdd" visible="@ViewBag.save">扫描录入</li>        
        <li class="separator"></li>
        <li id ="uncheck" iconCls="icon-unlock" onclick="checkBillUn" visible="@ViewBag.uncheck">反审核</li>
    </ul>

    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("form1");
        var grid = mini.get("datagrid1");      
        var uID = parent.window.getSystemAppID();
        var uCode = parent.window.getSystemAppCode();
        var uName = parent.window.getSystemAppName();
        var LastField = "mFRemark";
        var sumFields = "mFQty,mFSetQty,mFAmount,mFQty_Pur";

        $(function () {
            var oBox = document.getElementById("scan");
            var oBar = document.getElementById("title");
            if(id==0)
                BillState(0);
            InitScan();
            startDrag(oBar, oBox);
            InitGrid('InsData');
        });

        var id = getQueryString("billid");
        if (id != null) {
            mini.getbyName("KInterID").setValue(id);
        }        
        var datatype = getQueryString("datatype");      

        LoadData();

        function LoadData() {
            var minterid = mini.getbyName("KInterID").value;
            $.ajax({
                url: '../Bill/GetBillData',
                data: { mSystemAppID: uID, mBillID: minterid, mDataType: datatype },
                dataType: 'text',
                async: false,
                success: function (text) {
                    var dataR = mini.decode(text);
                    grid.setData(dataR.datadetail);
                    if (dataR.datamaster.length > 0) {
                        var mdata = dataR.datamaster[0];
                        form.setData(mdata);
                        mini.getbyName("FSupplyItemID").setValue(mdata.FSupplyID);
                        mini.getbyName("FSupplyItemID").setText(mdata.FSupplyNumber);
                        mini.getbyName("FStockID").setValue(mdata.FStockID);
                        mini.getbyName("FStockID").setText(mdata.FStockNumber);
                        mini.getbyName("FBillNO_Pur").setValue(mdata.KInterID_Pur);
                        mini.getbyName("FBillNO_Pur").setText(mdata.FBillNO_Pur);
                        mini.getbyName("KInterID_Pur").setValue(mdata.KInterID_Pur);
                        if (mdata.FCheckFlag == true) {
                            BillState(2);
                            mini.get("ScanAdd").setEnabled(false);
                            mini.get("import").setEnabled(false);
                        }
                        else {
                            BillState(1);
                            if (minterid == 0) {
                                mini.get("ScanAdd").setEnabled(true);
                                mini.get("import").setEnabled(true);
                            }
                            else {
                                mini.get("ScanAdd").setEnabled(false);
                                mini.get("import").setEnabled(false);
                            }
                        }
                        if ((mdata.KInterID == "0") || (mdata.KInterID == null)) {
                            newBills();
                            mini.get("ScanAdd").setEnabled(true);
                            mini.get("import").setEnabled(true);
                        }
                    }
                    else {
                        newBills();
                    }
                }
            });
        }

        function modifys() {
            modify();
            mini.get("ScanAdd").setEnabled(true);
            mini.get("import").setEnabled(true);
            var KInterID_Pur = mini.getbyName("KInterID_Pur").getValue();
            if (KInterID_Pur > 0) {
                grid.updateColumn("mFNumber", { readOnly: true });
                mini.get("addrow").setEnabled(false);
                mini.get("delrow").setEnabled(false);
                mini.get("ScanAdd").setEnabled(false);
                mini.get("import").setEnabled(false);
                mini.get("FBillNO_Pur").setEnabled(false);                
            }
            else {
                grid.updateColumn("mFNumber", { readOnly: false });
            }
        }
        
        function newBills() {
            NewBill();
            var nowDate = new Date();
            mini.getbyName("FBillDate").setValue(nowDate);
            mini.getbyName("FDate").setValue(nowDate);
            mini.getbyName("FBillNo").setValue('');
            mini.getbyName("FRemark").setValue('');
            mini.getbyName("txtCheckFlag").setValue('');
            mini.get("ScanAdd").setEnabled(true);
            mini.get("import").setEnabled(true);
            grid.updateColumn("mFNumber", { readOnly: false });
            mini.getbyName("FBillNO_Pur").setValue("0");
            mini.getbyName("FBillNO_Pur").setText("");
            mini.getbyName("KInterID_Pur").setValue("0");
        }

        function checkValid() {
            if ((mini.getbyName("FBillerID").getValue() == "") || (mini.getbyName("FBillerID").getValue() == "0")) {
                var newbillerid = parent.window.getSystemAppID();
                mini.getbyName("FBillerID").setValue(newbillerid);
            }

            var MainData = form.getData();
            if (MainData.FSupplyItemID.toString() == "") {
                mini.showTips({ content: "<b>保存失败</b> <br/>供应商不能空值!", state: "danger", x: "center", y: "top", timeout: 3000 });
                return false;
            }
            if (MainData.FStockID.toString() == "") {
                mini.showTips({ content: "<b>保存失败</b> <br/>门店不能空值!", state: "danger", x: "center", y: "top", timeout: 3000 });
                return false;
            }
            return true;
        }

        function saveBill() {
            BillState(1);//先锁定
            mini.get("ScanAdd").setEnabled(false);
            if (checkValid() == false) {
                BillState(4);//先锁定
                mini.get("ScanAdd").setEnabled(true);
                return;
            }
            var MainData = form.getData();
            var cDate = mini.getbyName("FDate").getFormValue();
            var KInterID_Pur = mini.getbyName("KInterID_Pur").getValue();
            var rCnt = grid.getData().length;
            var sBillNo = MainData.FBillNo;

            var mjson = "[{'KInterID':'" + MainData.KInterID + "',";
            mjson = mjson + "'FBillNo':'" + MainData.FBillNo + "',";
            mjson = mjson + "'FSystemAppID':'" + uID + "',";
            mjson = mjson + "'FSupplyID':'" + MainData.FSupplyItemID + "',";
            mjson = mjson + "'FStockID':'" + MainData.FStockID + "',";            
            mjson = mjson + "'KInterID_Pur':'" + KInterID_Pur + "',";
            var FBillNO_Pur = mini.getbyName("FBillNO_Pur").getText();
            mjson = mjson + "'FBillNO_Pur':'" + FBillNO_Pur + "',";
            mjson = mjson + "'FDate':'" + cDate + "',";
            mjson = mjson + "'FDataType':'" + datatype + "',";
            mjson = mjson + "'FRemark':'" + MainData.FRemark + "',";
            var json = "'goods_list':[";
            var datarow = 0;
            for (var i = 0; i < rCnt; i++) {
                var rs = grid.getRow(i);
                if (typeof (rs.mFNumber) == "undefined") continue;
                if (datarow > 0)
                    js = ",{";
                else
                    js = "{"              
                js = js + '"mFItemID":' + rs.mFItemID + ",";
                var qty = typeof (rs.mFQty) == "undefined" ? 0 : rs.mFQty;
                js = js + '"mFQty":' + qty + ",";
                var mFSetQty = typeof (rs.mFSetQty) == "undefined" ? 0 : rs.mFSetQty;
                js = js + '"mFSetQty":' + mFSetQty + ",";
                var price = typeof (rs.mFPrice) == "undefined" ? 0 : rs.mFPrice;
                js = js + '"mFPrice":' + price + ",";
                var money = typeof (rs.mFAmount) == "undefined" ? 0 : rs.mFAmount;
                js = js + '"mFAmount":' + money + ",";
                var remark = typeof (rs.mFRemark) == "undefined" ? "" : rs.mFRemark;
                js = js + '"mFRemark":"' + remark + '",';
                var mFEntryID_Pur = typeof (rs.mFEntryID_Pur) == "undefined" ? 0 : rs.mFEntryID_Pur;
                js = js + '"mFEntryID_Pur":' + mFEntryID_Pur + ",";
                var mFInterID_Pur = typeof (rs.mFInterID_Pur) == "undefined" ? 0 : rs.mFInterID_Pur;
                js = js + '"mFInterID_Pur":' + mFInterID_Pur + ",";
                var mFBillNo_Pur = typeof (rs.mFBillNo_Pur) == "undefined" ? "" : rs.mFBillNo_Pur;
                js = js + '"mFBillNo_Pur":"' + mFBillNo_Pur + '",';
                var mFBatchNumber = typeof (rs.mFBatchNumber) == "undefined" ? "" : rs.mFBatchNumber;
                js = js + '"mFBatchNumber":"' + mFBatchNumber + '",';
                var mFQty_Pur = typeof (rs.mFQty_Pur) == "undefined" ? 0 : rs.mFQty_Pur;
                js = js + '"mFQty_Pur":' + mFQty_Pur + ",";
                var mFWarranty = "";
                if (rs.mFWarranty!=null)
                    mFWarranty = typeof (rs.mFWarranty) == "undefined" ? "" : rs.mFWarranty.getFullYear() + '-' + (rs.mFWarranty.getMonth() + 1) + '-' + rs.mFWarranty.getDate();
                js = js + '"mFWarranty":"' + mFWarranty + '",';

                var mFMakedate = "";
                if (rs.mFMakedate!=null)
                    mFMakedate =typeof (rs.mFMakedate) == "undefined" ? "" : rs.mFMakedate.getFullYear() + '-' + (rs.mFMakedate.getMonth() + 1) + '-' + rs.mFMakedate.getDate();
                js = js + '"mFMakedate":"' + mFMakedate + '"';
                js = js + "}"
                json = json + js;
                datarow = datarow + 1;
            }
            if (datarow == 0)
            {
                mini.showTips({ content: "<b>保存失败</b> <br/>没有要保存的数据!", state: "danger", x: "center", y: "top", timeout: 5000 });
                BillState(4);
                mini.get("ScanAdd").setEnabled(true);
                return false;
            }
            json = json + "]";
            mjson = mjson + json + "}]";
            $.ajax({
                url: '../Bill/SaveBillData_Ins',
                data: { mdatajson: mjson },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    if (ret.id > 0 && ret.FBillNo != '') {
                        mini.getbyName("KInterID").setValue(ret.id);
                        mini.getbyName("FBillNo").setValue(ret.FBillNo);
                        mini.showTips({ content: "<b>保存成功</b>", state: "success", x: "center", y: "top", timeout: 3000 });
                        BillState(1);
                        mini.get("ScanAdd").setEnabled(false);
                        mini.get("import").setEnabled(false);
                        //confirm("是否现在审核");
                        //if (mini.confirm("是否现在审核"))
                        //    checkBill();
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                        BillState(4);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }

        function confirm(text) {
            mini.confirm(text, "提示",
              function (action) {
                  if (action == "ok") {
                      checkBill();
                  }
              }
          );
        }

        function onButtonEditMy(e) {
            ShowGoodsMy("");
        }

        function onValueChangedMy(e) {
            ShowGoodsMy(e.value);
        }


        function ShowGoodsMy(txtValue) {
            mini.get("save").setEnabled(true);
            var FObjectID = mini.getbyName("FSupplyItemID").getValue();
            var FStockID = mini.getbyName("FStockID").getValue();            
            var json = "[{";
            json = json + "'FClassID':" + "'0',";
            json = json + "'FObjectID':" + "'" + FObjectID + "',";
            json = json + "'FStockID':" + "'" + FStockID + "',";
            json = json + "'FBillType':" + "'" + datatype + "',";
            json = json + "'FSupplierID':" + "'-1',";
            json = json + "'FNumber':'" + txtValue + "',";
            json = json + "'FName':'" + "" + "',";
            json = json + "'FSystemAppID':'" + uID + "'}]";
            if ((txtValue != null) && (txtValue != "")) {
                $.post("../Bill/GetBillGoodss", { datajson: json }, function (data) {
                    var ret = mini.decode(data);
                    if (ret.data.length == 1) {
                        var row = grid.getSelected();
                        var action = ret.data[0];
                        var newaction = Extra({
                            mFItemID: action.FItemID, mFNumber: action.FNumber, mFName: action.FName, mFModel: action.FSpec,
                            mFUnitName: action.FUnitName, mFQty: row == null ? 0 : row.mFQty, mFPrice: action.FPrice, mFCode: action.FCode,
                            mFStockQty: action.FStockQty, mFPosPrice: action.FPosPrice, mFPurPrice: action.FPurPrice, 
                            mFEntryID_Pur: 0, mFInterID_Pur: 0, mFQty_Pur: 0, mFBillNO_Pur: ''
                        });
                        grid.updateRow(row, newaction);
                        if ((row.mFQty != "NaN") && (row.mFQty != 0)) {
                            grid.updateRow(row, {
                                mFAmount: row.mFQty * action.FPrice,
                                mFPurAmount: row.mFQty * action.FPurPrice,
                                mFPosAmount: row.mFQty * action.FPosPrice
                            });
                        }
                    }
                    else {
                        ShowGoodsWinMy(txtValue);
                    }
                });
            }
            else {
                ShowGoodsWinMy(txtValue);
            }
        }

        //选择商品表
        function ShowGoodsWinMy(txtValue) {
            var FObjectID = mini.getbyName("FSupplyItemID").getValue();
            var FStockID = mini.getbyName("FStockID").getValue();
            mini.open({
                url: "../Bill/GetBillGoods",
                title: "选择商品", width: 900, height: 500,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { key: txtValue, mBillType: datatype, mStockID: FStockID, FObjectID: FObjectID };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    if (action) {
                        var row = grid.getSelected();
                        for (var i = 0, l = action.length; i < l; i++) {
                            var rw = action[i];
                            if (typeof (row.mFItemID) != "undefined") {
                                var ix = grid.indexOf(row);
                                ix++;
                                if (ix >= grid.getData().length) {
                                    var newRow = {
                                        mFItemID: rw.FItemID, mFNumber: rw.FNumber, mFName: rw.FName, mFModel: rw.FSpec,
                                        mFUnitName: rw.FUnitName, mFQty: 0, mFPrice: rw.FPrice, mFCode: rw.FCode,
                                        mFStockQty: rw.FStockQty, mFPosPrice: rw.FPosPrice, mFPurPrice: rw.FPurPrice,
                                        mFEntryID_Pur: 0, mFInterID_Pur: 0, mFQty_Pur: 0, mFBillNO_Pur: ''
                                    };
                                    grid.addRow(Extra(newRow), grid.getData().length);
                                    row = grid.getRow(ix);
                                }
                                else {
                                    row = grid.getRow(ix);
                                    grid.cancelEdit();
                                    grid.updateRow(row, Extra({
                                        mFItemID: rw.FItemID, mFNumber: rw.FNumber, mFName: rw.FName, mFModel: rw.FSpec,
                                        mFUnitName: rw.FUnitName, mFQty: 0, mFPrice: rw.FPrice, mFCode: rw.FCode,
                                        mFStockQty: rw.FStockQty, mFPosPrice: rw.FPosPrice, mFPurPrice: rw.FPurPrice,
                                        mFEntryID_Pur: 0, mFInterID_Pur: 0, mFQty_Pur: 0, mFBillNO_Pur: ''
                                    }));
                                }
                            }
                            else {
                                grid.cancelEdit();
                                var arow = {
                                    mFItemID: rw.FItemID, mFNumber: rw.FNumber, mFName: rw.FName, mFModel: rw.FSpec,
                                    mFUnitName: rw.FUnitName, mFQty: 0, mFPrice: rw.FPrice, mFCode: rw.FCode,
                                    mFStockQty: rw.FStockQty, mFPosPrice: rw.FPosPrice, mFPurPrice: rw.FPurPrice,
                                    mFEntryID_Pur: 0, mFInterID_Pur: 0, mFQty_Pur: 0, mFBillNO_Pur: ''
                                };
                                var newRow = Extra(arow);
                                grid.updateRow(row, newRow);
                            }
                        }
                    }
                }
            });
        }

        function onGetSourceBill() {
            mini.open({
                url: "../Bill/FindBill",
                title: "查看单据", width: 900, height: 530,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { BillKind: "1013" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {                    
                    if (action) {                        
                        if ((action.KInterID == null) || (action.KInterID == "undefined")) return;
                        mini.getbyName("KInterID_Pur").setValue(action.KInterID);
                        LoadDataFromPur();
                    }
                }
            });
        }

        function LoadDataFromPur() {
            var minterid = mini.getbyName("KInterID_Pur").value;
            $.ajax({
                url: '../Bill/GetBillData',
                data: { mSystemAppID: uID, mBillID: minterid, mDataType: "1013" },
                dataType: 'text',
                async: false,
                success: function (text) {
                    var dataR = mini.decode(text);
                    grid.setData(dataR.datadetail);
                    if (dataR.datamaster.length > 0) {
                        var mdata = dataR.datamaster[0];
                        form.setData(mdata);
                        mini.getbyName("KInterID").setValue("0");
                        mini.getbyName("FBillNo").setValue("");
                        mini.getbyName("FStockID").setValue(mdata.FStockID);
                        mini.getbyName("FStockID").setText(mdata.FStockNumber);
                        mini.getbyName("FStockName").setValue(mdata.FStockName);
                        mini.getbyName("FSupplyItemID").setValue(mdata.FSupplyID);
                        mini.getbyName("FSupplyItemID").setText(mdata.FSupplyNumber);
                        mini.getbyName("FSupplyName").setValue(mdata.FSupplyName);
                        mini.getbyName("FBillNO_Pur").setValue(mdata.KInterID);
                        mini.getbyName("FBillNO_Pur").setText(mdata.FBillNo);
                        mini.getbyName("KInterID_Pur").setValue(mdata.KInterID);
                        grid.updateColumn("mFNumber", { readOnly: true });                        
                        BillState(4);
                        mini.get("addrow").setEnabled(false);
                        mini.get("delrow").setEnabled(false);
                        mini.get("ScanAdd").setEnabled(false);
                        mini.get("import").setEnabled(false);
                    }
                }
            });
        }

        function ExcelImport() {
            var FSystemAppID = parent.window.getSystemAppID();
            mini.open({
                url: "../Bill/ImportData?mDataType=3&mSystemAppID=" + FSystemAppID + "&FStockID=" + mini.getbyName("FStockID").getValue(),
                title: "Excel导入", width: 450, height: 200,
                ondestroy: function (action) {
                    if (action == "close")
                        return;
                    if (action) {
                        if (action.length > 0) {
                            if (grid.getData().length > 0) {
                                if (grid.getData()[grid.getData().length-1].mFNumber == undefined) {
                                    var row = grid.getRow(grid.getData().length-1);
                                    grid.removeRow(row, false);
                                }
                            }
                            for (var i = 0, l = action.length; i < l; i++) {
                                var rw = action[i];
                                        var newRow = {
                                            mFItemID: rw.mFItemID, mFNumber: rw.mFNumber, mFName: rw.mFName, mFModel: rw.mFModel,
                                            mFUnitName: rw.mFUnitName, mFQty: rw.mFQty, mFSetQty: rw.mFSetQty, mFPrice: rw.mFPrice,
                                            mFCode: rw.mFCode, mFAmount: rw.mFPrice * rw.mFQty, mFRemark: rw.mFRemark,
                                            mFEntryID_Pur: 0, mFInterID_Pur: 0, mFQty_Pur: 0, mFBillNO_Pur: ''
                                        };
                                        grid.addRow(newRow, grid.getData().length);
                            }
                            BillState(4);
                            mini.get("ScanAdd").setEnabled(true);
                        }
                    }
                }
            });        
        }

        function onCellCommitEditMy(e) {
            var row = e.record;
            var total = 0;
            var alltotal = 0; //合计金额,总计           
            if (typeof (row.mFName) == "undefined") {
                return;
            }

            mini.get("save").setEnabled(true);//编辑后保存按钮可用

            if (e.field == "mFPrice" || e.field == "mFQty") {
                if (e.field == "mFPrice") {
                    total = row.mFQty * e.value;
                }

                if (e.field == "mFQty") {
                    if ((e.value > row.mFQty_Pur) && (row.mFQty_Pur > 0)) {
                        e.cancel = true;
                        mini.alert("输入的数量不能大于订单数量");
                        return;
                    }

                    total = row.mFPrice * e.value;
                    row.mFQty = e.value;
                }
                total = total.toFixed(2);
                alltotal = alltotal.toFixed(2)

                var mPurAmount = row.mFPurPrice * row.mFQty;
                mPurAmount = mPurAmount.toFixed(2);

                var mPosAmount = row.mFPosPrice * row.mFQty;
                mPosAmount = mPosAmount.toFixed(2);

                grid.updateRow(row, { mFAmount: total, mFPurAmount: mPurAmount, mFPosAmount: mPosAmount });
                //grid.updateRow(row, { mFAmount: total });
            }
            if (e.field == "mFAmount") {
                total = e.value / row.mFQty;
                total = total.toFixed(2);
                alltotal = alltotal.toFixed(2);
                if (total != "NaN") {
                    grid.updateRow(row, { mFPrice: total });
                }
            }
        }

        function ExtraFunc(obj) {
            obj.mFSetQty = 0;
            return obj;
        }

    </script>

</body>